package com.steve.xfood.dataobject.mapper;

import com.steve.xfood.dataobject.ProductCategory;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author steve
 * @date 2020/5/29 5:49 上午
 */
public interface ProductCategoryMapper {

    /**
     * 插入类目(通过Map)
     * @param map
     * @return
     */

    @Insert("insert into product_category(category_name, category_type) values (#{categoryName, jdbcType=VARCHAR}, #{categoryType, jdbcType=INTEGER})")
    int insertByMap(Map<String, Object> map);

    /**
     * 插入类目（通过对象）
     * @param productCategory
     * @return
     */
    @Insert("insert into product_category(category_name, category_type) values (#{categoryName, jdbcType=VARCHAR}, #{categoryType, jdbcType=INTEGER})")
    int insertByObject(ProductCategory productCategory);

    /**
     * 根据类目类型查找商品类目
     * @param categoryType
     * @return
     */
    @Select("select * from product_category where category_type=#{categoryType}")
    @Results({
            @Result(column = "category_id", property = "categoryId"),
            @Result(column = "category_name", property = "categoryName"),
            @Result(column = "category_type", property = "categoryType")
    })
    ProductCategory findCategoryType(Integer categoryType);

    /**
     * 根据类目名称查找商品类目
     * @param categoryName
     * @return
     */
    @Select("select * from product_category where category_name=#{categoryName}")
    @Results({
            @Result(column = "category_id", property = "categoryId"),
            @Result(column = "category_name", property = "categoryName"),
            @Result(column = "category_type", property = "categoryType")
    })
    List<ProductCategory> findCategoryName(String categoryName);

    /**
     * 通过类目类型修改商品类目名称
     * 多个参数时，需要加上@Param注解
     * @param categoryName
     * @param categoryType
     * @return
     */
    @Update("update product_category set category_name=#{categoryName} where category_type=#{categoryType}")
    int updateByCategoryType(@Param("categoryName") String categoryName,
                             @Param("categoryType") Integer categoryType);

    /**
     * 通过商品类目实体类修改商品类目
     * @param productCategory
     * @return
     */
    @Update("update product_category set category_name=#{categoryName} where category_type=#{categoryType}")
    int updateByProductCategory(ProductCategory productCategory);

    /**
     * 根据类目类型删除商品类目
     * @param categoryType
     * @return
     */
    @Delete("delete from product_category where category_type=#{categoryType}")
    int deleteByCategoryType(Integer categoryType);

}
